using System.Collections.Generic;

namespace Luna.Core.Extensions
{
    public static class ArrayExtension
    {
        public static IEnumerable<T> SliceElements<T>(this T[] values, int start, int count)
        {
            int end = start + count - 1;

            if (start < 0)
            {
                start = 0;
            }
            if (end >= values.Length)
            {
                end = values.Length - 1;
            }
            for (int i = start; i <= end; i++)
            {
                yield return values[i];
            }
        }

        public static IEnumerable<T> GetFromEnd<T>(this T[] array, int count)
        {
            for (int i = array.Length - 1; i > array.Length - 1 - count; i--)
            {
                yield return array[i];
            }
        }

        public static bool IsNullOrEmpty<T>(this T[] array)
        {
            return array == null || array.Length == 0;
        }
    }
}